package com.study.designmodes.enums;

/**
 * @author yangyanbin
 * @since 20221108
 **/

import java.util.HashMap;
import java.util.Map;

public enum HrssAreaCodeEnum {
    BEI_JING("11", "110000", "北京", true, false),
    TIAN_JIN("12", "120000", "天津", true, false),
    SHANG_HAI("31", "310000", "上海", true, false),
    CHONG_QING("50", "500000", "重庆", true, false),
    DA_LIAN("2102", "210200", "大连", false, true),
    NING_BO("3302", "330200", "宁波", false, true),
    XIA_MEN("3502", "350200", "厦门", false, true),
    QING_DAO("3702", "370200", "青岛", false, true),
    SHEN_ZHEN("4403", "440300", "深圳", false, true),
    GUANG_DONG_DONG_GUAN("4419", "441900", "广东东莞", false, false),
    CHENG_DU("5101", "510100", "成都", false, false),
    MIAN_YANG("5107", "510700", "绵阳", false, false),
    LE_SHAN("5111", "511100", "乐山", false, false),
    HE_BEI("13", "130000", "河北", false, false),
    SHAN_XI("14", "140000", "山西", false, false),
    NEI_MENG("15", "150000", "内蒙", false, false),
    LIAO_NING("21", "210000", "辽宁", false, false),
    JI_LIN("22", "220000", "吉林", false, false),
    HEI_LONG_JIANG("23", "230000", "黑龙江", false, false),
    JIANG_SU("32", "320000", "江苏", false, false),
    ZHE_JIANG("33", "330000", "浙江", false, false),
    AN_HUI("34", "340000", "安徽", false, false),
    FU_JIAN("35", "350000", "福建", false, false),
    JIANG_XI("36", "360000", "江西", false, false),
    SHAN_DONG("37", "370000", "山东", false, false),
    HE_NAN("41", "410000", "河南", false, false),
    HU_BEI("42", "420000", "湖北", false, false),
    HU_NAN("43", "430000", "湖南", false, false),
    GUANG_DONG("44", "440000", "广东", false, false),
    GUANG_XI("45", "450000", "广西", false, false),
    HAI_NAN("46", "460000", "海南", false, false),
    SI_CHUAN("51", "510000", "四川", false, false),
    GUI_ZHOU("52", "520000", "贵州", false, false),
    YUN_NAN("53", "530000", "云南", false, false),
    XI_ZANG("54", "540000", "西藏", false, false),
    SHAAN_XI("61", "610000", "陕西", false, false),
    GAN_SU("62", "620000", "甘肃", false, false),
    QING_HAI("63", "630000", "青海", false, false),
    NING_XIA("64", "640000", "宁夏", false, false),
    XIN_JIANG("65", "650000", "新疆", false, false),
    UNKNOWN("0", "000000", "未知", false, false);

    private static final Map<String, HrssAreaCodeEnum> AREA_CODE_ENUM = new HashMap();
    private static final Map<String, HrssAreaCodeEnum> SHORT_AREA_CODE_ENUM = new HashMap();
    private final String shortAreaCode;
    private final String areaCode;
    private final String areaName;
    private final boolean direct;
    private final boolean single;

    public static HrssAreaCodeEnum getByCode(String areaCode) {
        return AREA_CODE_ENUM.containsKey(areaCode) ? (HrssAreaCodeEnum) AREA_CODE_ENUM.get(areaCode) : UNKNOWN;
    }

    public static HrssAreaCodeEnum getByShortCode(String shortAreaCode) {
        return SHORT_AREA_CODE_ENUM.containsKey(shortAreaCode) ? (HrssAreaCodeEnum) SHORT_AREA_CODE_ENUM.get(shortAreaCode) : UNKNOWN;
    }

    public static HrssAreaCodeEnum getByLocationCode(String locationCode) {

        String subAreaCode = locationCode.substring(0, 4) + "00";
        String areaCode = locationCode.substring(0, 2) + "0000";
        HrssAreaCodeEnum areaCodeEnum = (HrssAreaCodeEnum) AREA_CODE_ENUM.get(subAreaCode);
        if (null == areaCodeEnum) {
            areaCodeEnum = (HrssAreaCodeEnum) AREA_CODE_ENUM.get(areaCode);
        }

        return areaCodeEnum;
    }

    public String getShortAreaCode() {
        return this.shortAreaCode;
    }

    public String getAreaCode() {
        return this.areaCode;
    }

    public String getAreaName() {
        return this.areaName;
    }

    public boolean isDirect() {
        return this.direct;
    }

    public boolean isSingle() {
        return this.single;
    }

    public static boolean isSingle(String locationCode) {
        HrssAreaCodeEnum areaCodeEnum = getByLocationCode(locationCode);
        return areaCodeEnum == null ? false : areaCodeEnum.isSingle();
    }

    public static Map<String, HrssAreaCodeEnum> getAreaCodeEnum() {
        return AREA_CODE_ENUM;
    }

    public static Map<String, HrssAreaCodeEnum> getShortAreaCodeEnum() {
        return SHORT_AREA_CODE_ENUM;
    }

    private HrssAreaCodeEnum(String shortAreaCode, String areaCode, String areaName, boolean direct, boolean single) {
        this.shortAreaCode = shortAreaCode;
        this.areaCode = areaCode;
        this.areaName = areaName;
        this.direct = direct;
        this.single = single;
    }

    static {
        HrssAreaCodeEnum[] var0 = values();
        int var1 = var0.length;

        for (int var2 = 0; var2 < var1; ++var2) {
            HrssAreaCodeEnum areaCode = var0[var2];
            AREA_CODE_ENUM.put(areaCode.getAreaCode(), areaCode);
            SHORT_AREA_CODE_ENUM.put(areaCode.getShortAreaCode(), areaCode);
        }

    }
}

